﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace SimplePad
{
    public partial class SettingsForm : Form
    {
        //MainForm mForm;

        public SettingsForm()
        {
            //mForm = form;

            InitializeComponent();

            if (SimplePad.Properties.Settings.Default.General == null)
            {
                SimplePad.Properties.Settings.Default.General = new System.Collections.Specialized.StringDictionary();
            }

            loadSettings();

            this.hideInstrsPanel.CheckedChanged += new System.EventHandler(this.hideInstrsPanel_CheckedChanged);
            this.hideStateString.CheckedChanged += new System.EventHandler(this.hideStateString_CheckedChanged);
        }

        private void closeButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public void loadSettings()
        {
            foreach (DictionaryEntry kvp in SimplePad.Properties.Settings.Default.General)
            {                
                switch (kvp.Key.ToString())
                {
                    case "maintoolbar.visible":
                        this.hideInstrsPanel.Checked = !bool.Parse(kvp.Value.ToString());
                        break;
                    case "mainstatus.visible":
                        this.hideStateString.Checked = !bool.Parse(kvp.Value.ToString());
                        break;
                    case "mainmenu.visible":
                        this.hideMenuString.Checked = !bool.Parse(kvp.Value.ToString());
                        break;
                }
            }
        }

        private void setSettings(string key, string value)
        {
            if (SimplePad.Properties.Settings.Default.General.ContainsKey(key))
            {
                SimplePad.Properties.Settings.Default.General[key] = value;
            }
            else
            {
                SimplePad.Properties.Settings.Default.General.Add(key, value);
            }
            SimplePad.Properties.Settings.Default.Save();
        }

        private void hideInstrsPanel_CheckedChanged(object sender, EventArgs e)
        {
            setSettings("maintoolbar.visible", (!this.hideInstrsPanel.Checked).ToString());
        }

        private void hideStateString_CheckedChanged(object sender, EventArgs e)
        {
            setSettings("mainstatus.visible", (!this.hideStateString.Checked).ToString());
        }

        private void hideMenuString_CheckedChanged(object sender, EventArgs e)
        {
            setSettings("mainmenu.visible", (!this.hideMenuString.Checked).ToString());
        }
    }
}
